package defines

import (
	"strings"
)

// func GetName(names []*ast.Ident) string {
// 	for _, name := range names {
// 		return name.Name
// 	}
// 	return ""
// }

func ParseSQL(comment, dialect string) (sql, orderBy string) {
	lines := strings.Split(comment, "\n")
	sql = ""
	dialect += ":"
	for _, line := range lines {
		line = strings.TrimSpace(line)
		if sql == "" {
			if strings.Index(line, dialect) == 0 {
				sql = line[len(dialect):]
				continue
			}
			if strings.Index(line, "sql:") == 0 {
				sql = line[len("sql:"):]
				continue
			}
		}
		if orderBy == "" {
			if strings.Index(line, "orderby:") == 0 {
				orderBy = line[len("orderby:"):]
			}
		}
	}
	return
}

// func ParseSelectorExprType(se *ast.SelectorExpr, ptr bool) *objs.Type {
// 	// name := ""
// 	x, ok := se.X.(*ast.Ident)
// 	pkg := ""
// 	if ok {
// 		pkg = x.Name
// 	}
// 	if ptr {
// 		return objs.NewPtrType(pkg, se.Sel.Name)
// 	}
// 	return objs.NewType(pkg, se.Sel.Name)
// }
